#!/bin/bash

set +e

IFS=$'\n\n' 

IPs="10-0-1"
ALLIPs=" '$IPs-35'"


# JobsAll=`/usr/local/bin/lotus-miner sealing jobs | grep -e $ALLIPs`
JobsAll=`/usr/local/bin/lotus-miner sealing jobs`
# JobsAll=`ls -al`
JobsANum=0
SHENYU=0

ALL=0;
AP=0;
PC1=0;
PC2=0;
C1=0;
C2=0;
FIN=0;
GET=0;
OTHER=0;
# 185 65

BASENUM=11

GPU_P1_MAX_238=`expr $BASENUM + 0`;
GPU_P1_MAX_239=`expr $BASENUM - 2`;
GPU_P1_MAX_240=`expr $BASENUM - 1`;
GPU_P1_MAX_241=`expr $BASENUM + 0`;
GPU_P1_MAX_242=`expr $BASENUM + 0`;
GPU_P1_MAX_243=`expr $BASENUM + 0`;
GPU_P1_MAX_244=`expr $BASENUM + 0`;
GPU_P1_MAX_245=`expr $BASENUM + 0`;
GPU_P1_MAX_246=`expr $BASENUM + 0`;


Jobs_GPU_238=0
Jobs_GPU_239=0
Jobs_GPU_240=0
Jobs_GPU_241=0
Jobs_GPU_242=0
Jobs_GPU_243=0
Jobs_GPU_244=0
Jobs_GPU_245=0
Jobs_GPU_246=0


for i in $JobsAll
do
  
  if [ `echo $i  | awk '{print $6}'` == 'Task' ]; then
    continue
  fi

  Hos=`echo $i  | awk '{print $5$6}'`
  # 10-0-1-11PC2
  #echo $i
  # echo `echo $Hos ----`

  let ALL+=1

  Task=`echo $i  | awk '{print $6}'`

  # echo `echo $Task sssss`
  if [ "$Task" == "AP" ]; then
    let AP+=1
  elif [ "$Task" == "PC1" ]; then
    let PC1+=1
  elif [ "$Task" == "PC2" ]; then
    let PC2+=1
  elif [ "$Task" == "C1" ]; then
    let C1+=1
  elif [ "$Task" == "C2" ]; then
    let C2+=1
  elif [ "$Task" == "GET" ]; then
    let GET+=1
  elif [ "$Task" == "FIN" ]; then
    let FIN+=1
  else
    let OTHER+=1
  fi 


  if [[ ${Hos} == "10-0-1-238AP"  ]]; then
    let Jobs_GPU_238+=1
  elif [[ ${Hos} == "10-0-1-238PC1"  ]]; then
    let Jobs_GPU_238+=1
  elif [[ ${Hos} == "10-0-1-239AP"  ]]; then
    let Jobs_GPU_239+=1
  elif [[ ${Hos} == "10-0-1-239PC1"  ]]; then
    let Jobs_GPU_239+=1
  elif [[ ${Hos} == "10-0-1-240AP"  ]]; then
    let Jobs_GPU_240+=1
  elif [[ ${Hos} == "10-0-1-240PC1"  ]]; then
    let Jobs_GPU_240+=1
  elif [[ ${Hos} == "10-0-1-241AP"  ]]; then
    let Jobs_GPU_241+=1
  elif [[ ${Hos} == "10-0-1-241PC1"  ]]; then
    let Jobs_GPU_241+=1
  elif [[ ${Hos} == "10-0-1-242AP"  ]]; then
    let Jobs_GPU_242+=1
  elif [[ ${Hos} == "10-0-1-242PC1"  ]]; then
    let Jobs_GPU_242+=1
  elif [[ ${Hos} == "10-0-1-243AP"  ]]; then
    let Jobs_GPU_243+=1
  elif [[ ${Hos} == "10-0-1-243PC1"  ]]; then
    let Jobs_GPU_243+=1
  elif [[ ${Hos} == "10-0-1-244AP"  ]]; then
    let Jobs_GPU_244+=1
  elif [[ ${Hos} == "10-0-1-244PC1"  ]]; then
    let Jobs_GPU_244+=1
  elif [[ ${Hos} == "10-0-1-245AP"  ]]; then
    let Jobs_GPU_245+=1
  elif [[ ${Hos} == "10-0-1-245PC1"  ]]; then
    let Jobs_GPU_245+=1
  elif [[ ${Hos} == "10-0-1-246AP"  ]]; then
    let Jobs_GPU_246+=1
  elif [[ ${Hos} == "10-0-1-246PC1"  ]]; then
    let Jobs_GPU_246+=1
  
  fi 

 

done

echo ""
echo ""
echo "-----------密封工人-------------->"

echo "JobsANum": $JobsANum
echo "ALL": $ALL
echo "AP": $AP
echo "PC1": $PC1
echo "PC2": $PC2
echo "C1": $C1
echo "C2": $C2
echo "FIN": $FIN
echo "GET": $GET

echo "GPU_P1_MAX": $GPU_P1_MAX  " => " $Jobs_GPU
GPU_P1_MAX_238=`expr $BASENUM + 0`;

echo "Jobs_GPU_238": $GPU_P1_MAX_238  " => " $Jobs_GPU_238
echo "Jobs_GPU_239": $GPU_P1_MAX_239  " => " $Jobs_GPU_239
echo "Jobs_GPU_240": $GPU_P1_MAX_240  " => " $Jobs_GPU_240
echo "Jobs_GPU_241": $GPU_P1_MAX_241  " => " $Jobs_GPU_241
echo "Jobs_GPU_242": $GPU_P1_MAX_242  " => " $Jobs_GPU_242
echo "Jobs_GPU_243": $GPU_P1_MAX_243  " => " $Jobs_GPU_243
echo "Jobs_GPU_244": $GPU_P1_MAX_244  " => " $Jobs_GPU_244
echo "Jobs_GPU_245": $GPU_P1_MAX_245  " => " $Jobs_GPU_245
echo "Jobs_GPU_246": $GPU_P1_MAX_246  " => " $Jobs_GPU_246


if [ $Jobs_GPU_238 -le $GPU_P1_MAX_238 ]; then

  /usr/local/bin/lotus-miner  --miner-repo /home/ceshi/.lotusminer  sectors pledge 238
else
  echo "238组 密封工作已饱和..."
fi

if [ $Jobs_GPU_239 -le $GPU_P1_MAX_239 ]; then

  /usr/local/bin/lotus-miner  --miner-repo /home/ceshi/.lotusminer  sectors pledge 239
else
  echo "239组 密封工作已饱和..."
fi


# if [ $Jobs_GPU_240 -le $GPU_P1_MAX_240 ]; then

#   /usr/local/bin/lotus-miner  --miner-repo /home/ceshi/.lotusminer  sectors pledge 240
# else
#   echo "240组 密封工作已饱和..."
# fi


# if [ $Jobs_GPU_241 -le $GPU_P1_MAX_241 ]; then

#   /usr/local/bin/lotus-miner  --miner-repo /home/ceshi/.lotusminer  sectors pledge 241
# else
#   echo "241组 密封工作已饱和..."
# fi


# if [ $Jobs_GPU_242 -le $GPU_P1_MAX_242 ]; then

#   /usr/local/bin/lotus-miner  --miner-repo /home/ceshi/.lotusminer  sectors pledge 242
# else
#   echo "242组 密封工作已饱和..."
# fi


# if [ $Jobs_GPU_243 -le $GPU_P1_MAX_243 ]; then

#   /usr/local/bin/lotus-miner  --miner-repo /home/ceshi/.lotusminer  sectors pledge 243
# else
#   echo "243组 密封工作已饱和..."
# fi

# if [ $Jobs_GPU_244 -le $GPU_P1_MAX_244 ]; then

#   /usr/local/bin/lotus-miner  --miner-repo /home/ceshi/.lotusminer  sectors pledge 244
# else
#   echo "244组 密封工作已饱和..."
# fi

# if [ $Jobs_GPU_245 -le $GPU_P1_MAX_245 ]; then

#   /usr/local/bin/lotus-miner  --miner-repo /home/ceshi/.lotusminer  sectors pledge 245
# else
#   echo "245组 密封工作已饱和..."
# fi

# if [ $Jobs_GPU_246 -le $GPU_P1_MAX_246 ]; then

#   /usr/local/bin/lotus-miner  --miner-repo /home/ceshi/.lotusminer  sectors pledge 246
# else
#   echo "246组 密封工作已饱和..."
# fi

echo "<-----------密封工人--------------"
